//C11:ep11_7_1.c: three students scores,used dynamic linklist.
// create node.
#include <bits/types.h>
#include <stdio.h>
#include <malloc.h>
#define LEN sizeof(struct student_st)

struct student_st
{
    long num;
    float score;
    struct student_st *next;
};

int n;    // global variable
struct student_st *creat(void)
{
    struct student_st *head;
    struct student_st *p1, *p2;
    n = 0;
    p1 = p2 = (struct student_st*)malloc(LEN);
    
    printf("Enter num,score\n");
    scanf("%ld%f", &p1->num, &p1->score);
    head = NULL;

    while(p1->num != 0)
    {
        n = n + 1;
        if(n == 1)
        {
            head = p1;
        }
        else
        {
            p2->next = p1;
        }
        p2 = p1;
        p1 = (struct student_st*)malloc(LEN);
        scanf("%ld%f", &p1->num, &p1->score);
    }
    p2->next = NULL;
    return head;
}

void print(struct student_st *head);
int main() {
    struct student_st a,b,c, *head, *p;
    //creat();
    print(creat());
    printf("\nHello\n");
}

void print(struct student_st *head)
{
    struct student_st *p;
    printf("\nNow , these %d  records are:\n",n);
    p = head;
    if(head != NULL)
    {
        do{
            printf("%ld %5.2f\n", p->num, p->score);
            p = p->next;
        }while(p != NULL);
    }
}